package implementor;

import java.sql.Date;

import model.Balance;

import daoInterface.BalanceDao;
import dbhandeling.Crude;

public class BalanceImpl extends Crude implements BalanceDao{

	
	String className = new Balance().getClass().getName();
	
	@Override
	public void add(Balance balance) throws Exception {
		super.insert(balance);
		
	}

	@Override
	public void update(Balance balance) throws Exception {
		super.update(className, "sellerId", balance.getsellerId()+"", "balanceId", balance.getBalanceId()+"");
		super.update(className, "totalAmt", balance.getTotalAmt()+"", "balanceId", balance.getBalanceId()+"");
		super.update(className, "amtPaid", balance.getAmtPaid()+"", "balanceId", balance.getBalanceId()+"");
		super.update(className, "purchaseDate", balance.getPurchaseDate()+"","balanceId", balance.getBalanceId()+"");
	}

	@Override
	public void delete(Balance balance) {
		super.delete(className, "balanceId", balance.getBalanceId()+"");
		
	}

	@Override
	public Balance[] retrieveArray( String conditionField,
			String conditionValue) throws Exception {
		Object[] balance= super.retreiveArrayOnCondition(className, conditionField, conditionValue);
		Balance[]s=new Balance[balance.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Balance) balance[i];
		return s;
	}

	@Override
	public Balance[] retrieveAll() throws Exception {
		Object[] balance= super.retreiveAll(className);
		Balance[]s=new Balance[balance.length];
		
		for(int i=0;i<s.length;i++)
			s[i]=(Balance) balance[i];
		return s;
	}

	@Override
	public Balance retrieve( String conditionField,
			String conditionValue) throws Exception {
		Balance balance=(Balance) super.retreive(className, conditionField, conditionValue);
		return balance;
	}	


	@Override
	public Balance[] retrieveOnMultipleCond(Date fromdate, Date todate,
			String sellername) {
		// TODO Auto-generated method stub
		return null;
	}
	
	public int getAutoGenratedKey()
	{
		 int key=super.getAutoGenratedKey(className,"") ;
		 return key;
	}

}
